<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <!-- 引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <!-- 引入Vue -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
    <!-- import JavaScript -->
    <script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>

    <style>
        html, body {
            height: 100%;
            width: 100%;
            /*解决封面重复*/
            min-width: 1280px;
        }

        body {
            margin: 0;
            background-image: url("../../../../../../Project/CoolShark/src/main/resources/static/imgs/bg.jpg");
            /*设置背景为封面,大小不会改变*/
            background-size: cover;
            text-align: center;
        }

        h1 {
            font-size: 72px;
            color: #0096dc;
            margin-bottom: 0;
        }

        img {
            width: 100px
        }

        h2 {
            font-size: 32px;
            color: #0096dc;
            margin-bottom: 0;
        }

        .el-button {
            margin-right: 50px;
        }

        .el-button a {
            text-decoration: none;
            display: block;
            color: white;
        }
    </style>
</head>
<body>
<div id="app">
    <h1>欢迎来到酷鲨商城</h1>
    <img src="../../../../../../Project/CoolShark/src/main/resources/static/imgs/shark.png" alt="">
    <h2>CoolSharkMall</h2>
    <el-card style="width: 600px ;height: 300px;
    margin: 0 auto;background-color: rgba(255,255,255,0.3)">
        <!--label-width="80px":让label和文本框显示在一行中-->
        <el-form label-width="70px" style="width: 400px;margin: 50px auto">
            <el-form-item label="用户名">
                <el-input v-model="user.username" type="text" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="user.password" type="password" placeholder="请输入密码"></el-input>
            </el-form-item>
            <!-- 设置记住密码功能 -->
<!--            <el-form-item>-->
<!--                <el-checkbox v-model="user.rem">记住密码</el-checkbox>-->
<!--            </el-form-item>-->
            <el-form-item>
                <el-button type="primary" @click="login()">登录</el-button>
                <el-button type="primary">注册</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</div>
</body>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user:{
                    username:"",
                    password:"",
                    rem:false // 默认是打钩的false是不打钩
                }
            }
        },
        methods: {
            login(){
                // 发出异步请求
                axios.post("/login",v.user).then(function (response) {
                    if (response.data==1){
                        location.href="/";
                    }else if(response.data==2){
                        v.$message("用户名不存在!");
                    }else{
                        v.$message("密码错误!");
                    }
                })
            }
        },
        created:function (){
            // 取出cookie中的数据显示到页面中
            // 将字符串按照分好进行擦还分
            let arr = document.cookie.split(";");
            for (let cookie of arr){
                // 按照等号进行拆分
                let cookieArr = cookie.split("=");
                // 将值赋给那么和value并对其去除空格
                let name = cookieArr[0].trim();
                let value = cookieArr[1].trim();
                // 判断遍历数组时是遍历用户名还是密码
                if (name=="username"){
                    this.user.username=value;
                }else if (name  == "password"){
                    this.user.password=value;
                }
            }
        }
    })
</script>
</html>